<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="cuit.*" %>
<%@ page import="java.util.*"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>

<%
	String pageid = request.getParameter("curPage");
    if(pageid==null)
	{
		pageid="1";
	} 
	BookDAO bd = new BookDAO();
	Page p = new Page(Integer.parseInt(pageid),bd.getTotalCount());
	List<Book> Books = new ArrayList();
	Books = bd.getBookByPage(p);
	request.setAttribute("page", p);
	request.setAttribute("Books", Books);
	request.getRequestDispatcher("showbook.jsp");	
%>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name="bookFrom" action="addBook" method="post">
	书名：<input name="bookName" type="text"/><br/>
	封面：<input name="picUrl" type="text"/><br/>
	价格：<input name="price" type="text"/><br/>
	<input type="submit" value="保存" />
</form>

<c:forEach var="book" items="${Books}" >
	书号：<c:out value="${book.uuid}" /><br/>
	书名：<c:out value="${book.bookName}" /><br/>
	封面：<c:out value="${book.picUrl}" /><br/>
	价格：<c:out value="${book.price}" /><br/>
	<a href="deleteBook?id=${book.uuid}">删除此书</a>&nbsp;&nbsp;
	<a href="getBook?id=${book.uuid}">修改此书</a><br/>
</c:forEach>
<div>
 <a href="BookShow?curPage=1"> 首页</a>
 <c:choose>
 	<c:when test="${page.curPage == 1} ">
 	<a href="BookShow?curPage=${page.curPage }"> 上页</a>
 	</c:when>
 	<c:otherwise>
 	<a href="BookShow?curPage=${page.curPage-1 }"> 上页</a>
 	</c:otherwise>
 </c:choose>
 <c:choose>
 	<c:when test="${page.curPage == page.totalPageCount} ">
 	<a href="BookShow?curPage=${page.curPage }"> 下页</a>
 	</c:when>
 	<c:otherwise>
 	<a href="BookShow?curPage=${page.curPage+1 }"> 下页</a>
 	</c:otherwise>
 </c:choose>
 	<a href="BookShow?curPage=${page.totalPageCount }"> 尾页</a>
</div>
</body>
</html>